<?php
class Myh_Captcha_Image extends Zend_Captcha_Image
{
	public function __construct($options = null)
	{
		$this->setImgDir(CAPTCHA_PATH . '/images');
		$this->setImgUrl(CAPTCHA_URL . '/images');
		$this->setWordlen(6);
		$this->setFont(CAPTCHA_PATH . '/fonts/arial.ttf');
		
		$this->setWidth($options['width']);
		$this->setHeight($options['height']);
		$this->setFontSize($options['size']);
		$this->setTimeout('100');
		/*
		$colorsF = array(array(0, 0, 0), array(255, 255, 255));
		$colorsB = array(array(255, 0, 0), array(255, 255, 255));
			
		$this->setFontColor($colorsF);
		$this->setBackgroundColor($colorsB);
		*/
		$this->generate();
		$ns = new Zend_Session_Namespace('Zend_Form_Captcha_' . $this->getId());
		$nsd = new Zend_Session_Namespace('Zend_Form_Captcha_Delete');
		if($nsd -> captchaId){
			$this->RemoveImg($nsd -> captchaId);
		}
		$ns -> word = $this->getWord();
		$ns -> captchaId = $this->getId();
		$nsd -> captchaId = $this->getId();
	}
	public function RemoveImg($captchaID)
    {
    	$fileName = CAPTCHA_PATH . '/images/' . $captchaID . $this->getSuffix();
    	$upload = new Myh_File_Upload();
    	$upload -> RemoveFile($fileName);	
    }
}